package com.company.dcm.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.company.dcm.entity.R_ClothSheet;
import com.company.dcm.mapper.R_ClothSheetMapper;
import com.company.dcm.service.R_ClothSheetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class R_ClothSheetServiceImpl extends ServiceImpl<R_ClothSheetMapper, R_ClothSheet> implements R_ClothSheetService {
    @Autowired
    private R_ClothSheetMapper r_clothSheetMapper;

    /**
     *不含统计信息
     */
    @Override
    public R_ClothSheet getR_ClothSheetByDeviceCodeAndSerialNo(String deviceCode, String serialNo) {
        List<R_ClothSheet> list = r_clothSheetMapper.selectList(new LambdaQueryWrapper<R_ClothSheet>()
                .eq(R_ClothSheet::getDeviceCode,deviceCode)
                .eq(R_ClothSheet::getSerialNo,serialNo)
                .orderBy(true,false, R_ClothSheet::getId)
                .last("limit 1"));
        if(list.size()>0)return list.get(0);
        else return null;
    }

    /**
     * 按布号查询对应机号和serialNo
     */
    @Override
    public R_ClothSheet getDeviceCodeAndSerialByClothCode(String clothCode) {
        List<R_ClothSheet> list = r_clothSheetMapper.selectList(new LambdaQueryWrapper<R_ClothSheet>()
                .eq(R_ClothSheet::getClothCode,clothCode)
                .orderBy(true,false, R_ClothSheet::getId)
                .select(R_ClothSheet::getDeviceCode,R_ClothSheet::getSerialNo)
                .last("limit 1"));
        if(list.size()>0)return list.get(0);
        else return null;
    }
}
